#!/usr/bin/env python
# -*- coding:utf-8 -*-

from flask_restful import Api

from . import dictionary_blueprint
from api_1_0.dictionaryResource.dictionaryResource import DictionaryResource
from api_1_0.dictionaryResource.dictionaryOtherResource import DictionaryOtherResource

api = Api(dictionary_blueprint)

# 获取词典列表
api.add_resource(DictionaryResource, '/<dictionary_id>', '', endpoint='Dictionary')


@dictionary_blueprint.route('/update/<dictionary_id>', methods=['PUT'], endpoint='DictionaryUpdate')
def update(dictionary_id):
    return DictionaryOtherResource.sensitive_update(dictionary_id)


# 以文本文件添加词典
@dictionary_blueprint.route('/add', methods=['POST'], endpoint='DictionaryAdd')
def add_dictionary():
    return DictionaryOtherResource.add_dictionary()

# 删除词典
@dictionary_blueprint.route('/delete/<dictionary_id>', methods=['PUT'], endpoint='DictionaryDelete')
def delete_dictionary(dictionary_id):
    return DictionaryOtherResource.delete_dictionary(dictionary_id)

# 获取词典单词列表
@dictionary_blueprint.route('/getwords/<dictionary_id>', methods=['GET'], endpoint='DictionaryGetWords')
def get_words(dictionary_id):
    return DictionaryOtherResource.get_words(dictionary_id)


# 删除词典中某一个单词
@dictionary_blueprint.route('/delete_word/<dictionary_id>/<word_id>', methods=['PUT'], endpoint='DictionaryDeleteWord')
def delete_word(dictionary_id, word_id):
    return DictionaryOtherResource.delete_word(dictionary_id, word_id)


# 设置单词为题库
@dictionary_blueprint.route('/set_word_as_test/<dictionary_id>/<word_id>', methods=['POST'], endpoint='DictionarySetWordAsTest')
def set_word_as_test(dictionary_id,word_id):
    return DictionaryOtherResource.set_word_as_test(dictionary_id,word_id)


# 将单词从词典的题库中移除
@dictionary_blueprint.route('/cancel_word_as_test/<dictionary_id>/<word_id>', methods=['POST'], endpoint='DictionarCyancelWordAsTest')
def cancel_word_as_test(dictionary_id,word_id):
    return DictionaryOtherResource.cancel_word_as_test(dictionary_id,word_id)

# 根据词典名称或名称的一部分进行查找
@dictionary_blueprint.route('/search', methods=['POST'], endpoint='DictionarySearchByName')
def search_dictionaries_by_name():
    return DictionaryOtherResource.search_dictionaries_by_name()

# 根据单词或单词的一部分对某个词典进行查找
@dictionary_blueprint.route('/search_words/<dictionary_id>', methods=['POST'], endpoint='DictionarySearchWords')
def search_words_in_dictionary(dictionary_id):
    return DictionaryOtherResource.search_words_in_dictionary(dictionary_id)

# 重命名词典
@dictionary_blueprint.route('/rename/<dictionary_id>', methods=['PUT'], endpoint='DictionaryRename')
def rename_dictionary(dictionary_id):
    return DictionaryOtherResource.rename_dictionary(dictionary_id)


# 生成测试题
@dictionary_blueprint.route('/<dictionary_id>/generate-test', methods=['GET'], endpoint='DictionaryTestQuestions')
def generate_test_questions(dictionary_id):
    return DictionaryOtherResource.generate_test_questions(dictionary_id)

